using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace ThatsMeSDK.Core
{
	/// <summary>
	/// Xml Data Provider for the Core
	/// </summary>
	internal class XmlDataProvider : IDataProvider
	{
		private VBrowser fetcher;
		
		/// <summary>
		/// Creates a new instance of XmlDataProvider
		/// </summary>
		internal XmlDataProvider()
		{
			fetcher = new VBrowser(20000);
		}
		
		/// <summary>
		/// Load Xml data from the TM Api
		/// </summary>
		/// <param name="contentUri">Uri to the content you want to fetch</param>
		/// <returns>XmlDocument Object with the Data</returns>
		public XmlDocument LoadData(Uri contentUri)
		{
			XmlDocument xmldoc = new XmlDocument();
			
			string xmlData = fetcher.GetRequest(contentUri);
			xmldoc.LoadXml(xmlData);
			
			return xmldoc;
		}
		
		/// <summary>
		/// Load Xml data from the TM Api with a POST Request
		/// </summary>
		/// <param name="contentUri">Uri to the content you want to fetch</param>
		/// <param name="postdata">Post Data</param>
		/// <returns>XmlDocument Object with the Data</returns>
		public XmlDocument LoadDataByPost(Uri contentUri, byte[] postdata)
		{
			XmlDocument xmldoc = new XmlDocument();
			
			string xmlData = fetcher.PostRequest(contentUri, postdata);
			xmldoc.LoadXml(xmlData);
			
			return xmldoc;
		}
	}
}
